let $order = $("#thirdPage");
let $form = $order.find(".one main .form").eq(0);
let $select = $order.find(".one main .row").eq(0);

$("#datepicker").datepicker({
  dateFormat: "yy-mm-dd",
  minDate: new Date()
});


$select.children().click(function() {
  $form.find("#text").val($(this).text());
  $(this).addClass("active").siblings().removeClass("active");
});

$form.find("#btn").click(() => {
  send()
});

$form.find("#btn-w").click(() => {
  myFullpage.moveTo(3, 1)
});

get()

function get() {
  $.ajax({
    url: "http://localhost:82/info.php",
    type: "get",
    success(res) {
      if (res === 400) {
        return;
      }
      if (res) {
        
        let data = JSON.parse(res);
        console.log(data)
        $thirdPage.find(".two main #table tbody").html("");
        data.forEach(e => {
          $thirdPage.find(".two main #table tbody").append(
            `
              <tr>
                <td>${e.usr}</td>
                <td>${e.tel}</td>
                <td>${e.content}</td>
                <td>${e.time}</td>
              </tr>
            `
          )
        });
      }
    }
  });
}

function send() {
  let data = {
    usr: JSON.parse(localStorage.getItem("sign_in_state")).usr,
    content: $form.find("#text").val(),
    tel: $form.find("#tel").val(),
    time: $form.find("#datepicker").val()
  }
  $.ajax({
    url: "http://localhost:82/info.php",
    type: "post",
    data,
    success(res) {
      if (res == 200) {
        alert("提交成功");
        get();
      }
    },
    error(err) {
      console.log(err)
    }
  })
}

